#!/bin/bash

CASSANDRA_PASS=<%= @cassandra_pwd %>
CASSANDRA_IP=<%= @cassandra_ip %>
CASSANDRA_PORT=<%= @cassandra_port %>

if [[ $(nodetool status |tail -n2 | grep -Ev "^$"a) == *"UN"* ]]; then
    echo "exit" | cqlsh -u cassandra -p $CASSANDRA_PASS $CASSANDRA_IP $CASSANDRA_PORT > /dev/null 2>&1
    rc=$?
     if [[ $rc != 0 ]]; then exit $rc; fi
  fi
  exit 0;
else
  echo "Not Up";
  exit 1;
fi

